const connection = require('../database/dataBase')

class HomeService {
  // 获取首页轮播图
  async getHomeSwiper() {
    const sql = `SELECT id, url, title FROM swipers WHERE position='home';`
    const result = await connection.execute(sql)
    return result[0]
  }
  // 获取首页推荐文章
  async getRecommendArticles() {
    const sql = `SELECT id, title, date, tag, comment, imgUrl, artBody FROM homearticles WHERE position='recommend';`
    const result = await connection.execute(sql)
    return result[0]
  }
  // 获取首页推荐最新文章
  async getNewRecommendArticles() {
    const sql = `SELECT id, title, date, tag, comment, imgUrl FROM newhomearticles WHERE position='newrecommend';`
    const result = await connection.execute(sql)
    return result[0]
  }
}

module.exports = new HomeService()